package com.czd.support.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.czd.base.model.Paginate;
import com.czd.base.service.BaseService;
import com.czd.support.common.Configuration;
import com.czd.support.model.DataDictionary;
import com.czd.support.model.TreeModel;

/**
 * Created with IntelliJ IDEA.
 * Author: Jerry.hu
 * Create: Jerry.hu (14-9-18 22:21)
 * Description:
 * To change this template use File | Settings | File Templates.
 */
@Service
public class DataDictionaryService extends BaseService<DataDictionary>{
    public List<DataDictionary> dataDictionaries = new ArrayList<>();
    
    public Paginate queryForPaginate(DataDictionary dataDictionary){
    	dataDictionary.setPageSize(Configuration.getInstance().getDefault_page_size());
        return this.queryForPaginate(sqlId("queryForPaginate"),sqlId("questionCount"),dataDictionary);
    }

    /**
     * 获取所有的数据字典集合
     * @return
     */
    public List<DataDictionary> queryAllData(){
        if(dataDictionaries.size() == 0){
            dataDictionaries = this.selectList(sqlId("queryAllData"));
        }
        return dataDictionaries;
    }

    /**
     * 根据父级code 值，获取所有的子集数据字典
     * @param level 父级code
     * @return
     */
	public List<DataDictionary> queryListByCode(String level){
		return this.selectList(sqlId("queryListByCode"),level);
	}

    /**
     * 查询房间的板块信息
     * @param level 房间板块的父级code
     * @return
     */
    public List<DataDictionary> queryRoomCategoryByLevel(String level){
        return this.selectList(sqlId("queryRoomCategoryByLevel"),level);
    }
    
    public boolean insertdataDictionary(DataDictionary dataDictionary){
        return this.insertAndReturnId(sqlId("insertdataDictionary"), dataDictionary) > 0;
    }
    
    public boolean del(DataDictionary dataDictionary){
        return this.delete(sqlId("del"),dataDictionary) ;
    }
    
    
    public DataDictionary findById(int id) {
        return this.selectOne(sqlId("findById"),id);
    }
    
    
    public boolean update(DataDictionary question) {
    	 
    	 
        return this.update(sqlId("update"),question);
        
    }
    
    public List<TreeModel> createHelpcenterTree() {
		return this.queryDao.getSqlSession().selectList(sqlId("createHelpcenterTree"));
	}
}
